zram: retry the device reset instead of dying silently at boot - #312
Open
kyleinoregon wants to merge 1 commit into
Open
zram: retry the device reset instead of dying silently at boot#312kyleinoregon wants to merge 1 commit into
kyleinoregon wants to merge 1 commit into
Conversation
The zram init script runs with "set -e". Right after "modprobe zram" udev opens the new block device to probe it, and while it is open the write to /sys/block/zram0/reset fails with EBUSY, which ends the script before mkswap and swapon ever run. Nothing reports the failure: the kernel log shows "zram: Added device" and then silence, and the machine runs with no swap at all. It is a race, so it does not happen on every boot. Wait for udev to settle when udevadm is available, then retry the reset for up to five seconds, and say so on the console if it still fails. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I found
My Centauri Carbon was running with no swap at all, although cosmos sets up a 200 % zram swap at boot.
freeshowedSwap: 0, and the kernel log hadzram: Added device: zram0followed by nothing: no capacity change, no "Adding … swap". Two reboots later it came up fine, a third time it failed again, so it is a race.I added a trace to
/etc/init.d/zramand caught the failing boot:Right after
modprobe zram, udev opens the new block device to probe it. While it is open, the write to/sys/block/zram0/resetfails with EBUSY, and because the script runs withset -eit just stops there, beforemkswapandswapon. Nothing reports it.Running the same script by hand a minute later works every time, which is why this is easy to miss.
Why it matters on this board
With 114 MB of RAM the machine idles at about 16 MB free. Without swap, an ordinary event like uploading a gcode file from the slicer while a print is starting (Moonraker spawns its metadata scanner) took free memory from 20 MB to 8 MB in a few seconds, Klipper stalled, and the toolhead MCU shut down with "Timer too close". With the zram swap active there is over 200 MB of headroom for exactly that. I suspect a fair number of "Timer too close" reports come from machines that lost this race at boot.
Change
udevadm settle --timeout=5after the modprobe when udevadm exists (it does on the image).Everything after the reset is unchanged: same algorithm, size, tuning and priority.
Tested
On a Centauri Carbon running 26.08.0. Before the change, with the traced script, the failure reproduced on one boot in four (trace above). After the change, three reboots in a row came up with the 234 MB zram swap active; the trace shows
udevadm settlereturning in about 60 ms and the reset then succeeding on the first try, so on this machine the settle alone closes the window and the retry loop is the safety net for boards without udevadm or with slower udev.